<!DOCTYPE html>
<html>

<head>

    <style>
        body {
            background-color: #f2f2f2;
        }

        .container {
            border: 2px solid #ccc;
            border-radius: 10px;
            margin-top: 50px;
            margin-left: 100px;
            width: 400px;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0px 0px 10px #ccc;
        }

        h1 {
            text-align: center;
        }

        input[type=text],
        input[type=password] {
            width: 100%;
            padding: 12px 20px;
            margin: 20px 0;
            /* display: inline-block; */
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        button {
            background-color: #4CAF50;
            color: white;
            padding: 14px 20px;
            margin: 8px 0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }

        button:hover {
            background-color: #45a049;
        }
    </style>
</head>

<body>
    <container>
        <div class="container">
            <input type="text" class="user" placeholder="请输入账号">
            <input type="text" class="pwd" placeholder="请输入密码">
            <button class="btn">注册</button>
        </div>
    </container>
</body>

<script src="./a.js"></script>

<script>

    $$('.btn').onclick = function () {
        const user = $$('.user').value;
        const pwd = $$('.pwd').value;


        const params = new URLSearchParams();

        params.append('username', user)
        params.append('password', pwd)

        console.log(params);


        fetch('http://121.43.116.41/php/reg.php', {
            method: 'POST',
            headers: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            body: params

        })
            .then(res => {
                console.log(res);
                return res.json()
            })
            .then(data => {
                const { msg, status } = data
                if (status) {
                    // location.href = 'login.html'

                } else {
                    alert(msg)
                }
            })
    }



</script>